package com.servlet;

import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.ChineseGifCaptcha;
import com.wf.captcha.GifCaptcha;
import com.wf.captcha.base.Captcha;
import com.wf.captcha.utils.CaptchaUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@WebServlet("/captcha")
public class CaptchaServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        GifCaptcha gifCaptcha = new GifCaptcha(130,48,4);
        CaptchaUtil.out(gifCaptcha, req, resp);
//        CaptchaUtil.out(5, req, resp);
//        // 设置宽、高、位数
//        CaptchaUtil.out(130, 48, 5, req, resp);

//         使用gif中文验证码
//        GifCaptcha gifCaptcha = new GifCaptcha(130,48,4);
//        ChineseGifCaptcha chineseGifCaptcha = new ChineseGifCaptcha(130, 48);
//        CaptchaUtil.out(chineseGifCaptcha, req, resp);

        //算数验证码
//        ArithmeticCaptcha arithmeticCaptcha = new ArithmeticCaptcha(130, 48);
//        arithmeticCaptcha.setLen(3);  // 几位数运算，默认是两位
//        arithmeticCaptcha.getArithmeticString();  // 获取运算的公式：3+2=?
//        arithmeticCaptcha.text();  // 获取运算的结果：5
//        arithmeticCaptcha.out(resp.getOutputStream());// 输出验证码
//        CaptchaUtil.out(arithmeticCaptcha,req,resp);
    }
}
